package top.jle.locker.config;

import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.Bean;
import org.noear.solon.annotation.Condition;
import org.noear.solon.annotation.Configuration;
import org.noear.solon.annotation.Inject;
import org.redisson.api.RedissonClient;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.config.TransportMode;
import org.redisson.solon.RedissonClientOriginalSupplier;

@Configuration
@Slf4j
public class RedissonConfig {

    @Bean(typed = true)
    @Condition(onClass = RedissonClient.class,onMissingBean = RedissonClient.class,onProperty = "${solon.jle.locker.enable}=true")
    public RedissonClient redissonClient(@Inject("${redisson}") RedissonClientOriginalSupplier supplier) {
        log.info("RedissonConfig.redissonClient init");
        return supplier.withConfig(config -> {
            config.setKeepPubSubOrder(true);
            config.setThreads(0);
            config.setNettyThreads(0);
            config.setCodec(JsonJacksonCodec.INSTANCE);
            config.setTransportMode(TransportMode.NIO);
        }).get();
    }
}
